<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>微购商城</title>
    <link href="${pageContext.request.contextPath}/static/css/css.css" rel="stylesheet" type="text/css"/>
    <script src="${pageContext.request.contextPath}/static/js/jquery.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/js.js" type="text/javascript"></script>
</head>

<body>
<div class="mianCont">
    <%--指定引入页面--%>
    <%@include file="common/_top.jsp" %>
    <div class="pnt">
        <div class="pntLeft">
            <h2 class="Title">所有商品分类
                <%--指定引入页面--%>
                <%@include file="common/_menu.jsp" %>
            </h2>
        </div>
        <div class="pntRight">
            <ul class="nav">
                <li><a href="${pageContext.request.contextPath}/index">商城首页</a></li>
                <li><a href="${pageContext.request.contextPath}/goods/list?categoryId=${categoryList.get(0).key}">${categoryList.get(0).value}</a></li>
                <li class="navCur"><a href="login.jsp">会员中心</a></li>
                <li><a href="help.html">帮助中心</a></li>
                <div class="clears"></div>
                <div class="phone">TEL：13264494458</div>
            </ul>
        </div>
        <div class="clears"></div>
    </div>
    <div class="positions">
        当前位置：<a href="index.html">首页</a> &gt; <a class="posCur" href="#">填写核对订单</a>
    </div>
    <div class="cont">
        <h4 class="orderTitle">
            收货地址
            <a href="addressAddUpdate.html" style="float: right;margin-right: 43px;margin-top: 5px;font-weight: normal;">[添加]</a>
        </h4>
        <table class="ord">
            <c:forEach items="${addressList}" var="address">
                <tr style="border-bottom: 1px dotted;">
                    <td style="width:10%;">
                        <c:if test="${address.moRen}">
                            <input type="radio" name="address" value="${address.id}" checked/> ${address.receiver}
                        </c:if>
                        <c:if test="${!address.moRen}">
                            <input type="radio" name="address" value="${address.id}"/> ${address.receiver}
                        </c:if>
                    </td>
                    <td style="width:80%;text-align: left;">
                        <span>
                            ${address.provinceName}，${address.cityName}，${address.countryName}，${address.addr}，${address.postcode}，${address.phone}
                        </span>
                        <span style="float: right;margin-right: 150px;color: #00aa00;">
                            <c:if test="${address.moRen}">
                                [默认]
                            </c:if>
                        </span>
                    </td>
                    <td>
                        <a href="addressAddUpdate.html">[修改]</a>
                    </td>
                </tr>
            </c:forEach>
        </table>

        <h4 class="orderTitle">支付方式</h4>
        <div style="margin-bottom: 15px;margin-left: 8px;margin-top: 5px;">
            <c:forEach items="${payMethodList}" var="payMethodEntry" varStatus="vs">
                <c:if test="${vs.count ==1}">
                    <input type="radio" name="payMethod" value="${payMethodEntry.key}" checked> ${payMethodEntry.value}
                </c:if>
                <c:if test="${vs.count !=1}">
                    <input type="radio" name="payMethod" value="${payMethodEntry.key}"> ${payMethodEntry.value}
                </c:if>
            </c:forEach>
        </div>
        <h4 class="orderTitle">购物清单</h4>
        <table class="orderList">
            <tr>
                <th style="with:5%;"><input type="checkbox" id="cbTrigger" checked/></th>
                <th style="with:50%;">商品</th>
                <th style="with:10%;">单价</th>
                <th style="with:15%;">数量</th>
                <th style="with:20%;">总金额</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${sessionScope.cart.cartItemVOs}" var="cartItem">
                <tr>
                    <td>
                        <input type="checkbox" name="idCB" checked id="${cartItem.id}"/>
                        <input type="hidden" name="id" value="${cartItem.id}">
                    </td>
                    <td>
                        <dl>
                            <dt>
                                <a href="${pageContext.request.contextPath}/goods?op=detailsFront&id=${cartItem.goodsId}">
                                    <img style="width: 85px;height: 85px;" src="${RESOURCES_SERVER}/goods/${cartItem.goodsPic}"/>
                                </a>
                            </dt>
                            <dd>${cartItem.goodsName}：${cartItem.goodsSellingPoint}</dd>
                            <div class="clears"></div>
                        </dl>
                    </td>
                    <td><strong class="red">${cartItem.goodsPrice}</strong>/${cartItem.goodsUnit}</td>
                    <td>
                        <div class="jia_jian">
                            <img class="jian" src="${RESOURCES_SERVER}/sys/frontend/jian.jpg" style="height: 25px;width: 21px;"/>
                            <input class="shuliang" type="text" value="${cartItem.amount}" id="amount${cartItem.id}"/>
                            <img class="jia" src="${RESOURCES_SERVER}/sys/frontend/jia.jpg" style="height: 25px;width: 21px;"/>
                            <input type="hidden" value="8">
                        </div>
                    </td>
                    <td><strong class="red">${cartItem.amount}</strong></td>
                    <td><strong class="red">￥${cartItem.money}</strong></td>
                    <td>
                        <a class="green" href="#">收藏</a><br/>
                        <a class="green" href="javascript:void(0)"  onclick="deleteCartItem(${cartItem.goodsId})">删除</a>
                    </td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="6">
                    <c:if test="${sessionScope.cart !=null && sessionScope.cart.cartItemVOs.size()>0}">
                        <div class="shanchu">
                            <span style="margin-right: 8px;">批量删除购物项</span>
                            <span style="margin-left: 8px;" onclick="clearCart()">清空购物车</span>
                        </div>
                    </c:if>
                    <c:if test="${sessionScope.cart ==null || sessionScope.cart.cartItemVOs.size()<=0}">
                        <div class="shanchu" style="text-align: center;">购物车为空</div>
                    </c:if>
                </td>
            </tr>
        </table>
        <table class="zongjia">
            <tr>
                <td style="text-align:right;width:120px;">总数量：</td>
                <td><strong class="red">${sessionScope.cart.totalAmount}</strong></td>
                <td style="text-align:right;width:120px;">合计格：</td>
                <td><strong class="red">￥ ${sessionScope.cart.totalMoney}</strong></td>
            </tr>
            <tr>
                <td colspan="8" style="height:50px;text-align: right;">
                    <img style="height: 32px;width: 142px;" src="${RESOURCES_SERVER}/sys/frontend/tijao.png" onclick="submitOrder()"/>
                </td>
            </tr>
        </table>
        <div class="clears"></div>
    </div>
    <%--指定引入页面--%>
    <%@include file="common/_bottom.jsp" %>
</div>
<a class="backTop" href="#">&nbsp;</a>
<script type="text/javascript">
    //复选框全选or取消全选
    $("#cbTrigger").change(function () {
        if ($("#cbTrigger").is(':checked')) {
            $("input[name='idCB']").prop("checked", true);
        } else {
            $("input[name='idCB']").prop('checked', false);
        }
    })

    //提交订单
    function submitOrder() {
        let params = "";

        //商品编号+数量
        $("input:checkbox[name='idCB']:checked").each(function (){
            let goodsId = $(this).attr("id");
            params += "&goodsId=" + goodsId;
            let amount = $("#amount" + goodsId).val();
            params += "&amount=" + amount;
        })
        console.log(params);

        //支付方式d
        let payMethodId = $("input[name='payMethod']:checked").val();
        params +="&payMethodId="+payMethodId;
        console.log(params);

        //收件地址
        let addressId = $("input[name='address']:checked").val();
        params +="&addressId="+addressId;
        console.log(params);

        document.location.href="${pageContext.request.contextPath}/order/genOrder?"+params;
    }
</script>
</body>
</html>
